<template>
  <div class="base_list">
    <div class="listItem" v-for="(item, index) of dataList" :key="index">
      <div class="itemLeft" @click="musicInfo(item, index)">
        <span class="leftSpan" v-if="!(songItemId == item.id)">{{ index + 1 }}</span>
        <img src="@/assets/loading.gif" alt="" v-if="songItemId == item.id" />
        <div class="leftDiv">
          <p class="divP">{{ item.name }}</p>
          <!-- v-for="(item1, index1) of item.ar" :key="index1"  -->
          <span class="divSpan"> {{ item.artists[0].name }}</span>
        </div>
      </div>
      <div class="itemRight">
        <svg class="iconR" aria-hidden="true" v-if="item.mvid != 0">
          <use xlink:href="#icon-shipin"></use>
        </svg>
        <svg class="iconR" aria-hidden="true">
          <use xlink:href="#icon-31liebiao"></use>
        </svg>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { withDefaults, defineProps, computed } from 'vue'
import { useStore } from '@/store'

const props = withDefaults(
  defineProps<{
    dataList: any
  }>(),
  {}
)
const store = useStore()
//拿到歌曲id和当前id做比对比对成功则添加类名实现特效
const songItemId = computed(() => store.state.songList.songItem.id)
//点击拿到歌曲的全部信息,再去请求歌词
const queryInfo = {
  pageName: '/lyric',
  id: '',
  loading: false
}
const musicInfo = (item: any, index: any) => {
  queryInfo.id = item.id
  const songItem = item
  const songItemAl = item.album.artist
  const songItemIndex = index
  store.commit('songList/changeSongItemInfo', { songItem, songItemAl, songItemIndex })
  store.dispatch('songList/getSongInfoList', queryInfo)
}
</script>

<style scoped lang="less">
.base_list {
  width: 100%;
  height: 100%;
  border: 1px solid #fff;
  box-sizing: border-box;
  border-top-left-radius: 0.2rem;
  border-top-right-radius: 0.2rem;
  background-color: #fff;
  overflow: hidden;
  .listItem {
    height: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    .itemLeft {
      display: flex;
      justify-content: space-between;
      align-items: center;
      .leftSpan {
        display: block;
        width: 0.6rem;
        height: 0.5rem;
        text-align: center;
        line-height: 0.5rem;
      }

      .leftDiv {
        display: flex;
        flex-direction: column;
        justify-items: center;

        padding-left: 0.2rem;
        .divP {
          width: 5rem;
          font-weight: 900;
          overflow: hidden;
          white-space: nowrap;
          text-overflow: ellipsis;
        }
        .divSpan {
          font-weight: normal;
          color: rgb(135, 134, 134);
        }
      }
    }
    .itemRight {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding-right: 0.2rem;
      .iconR {
        width: 0.5rem;
        height: 0.5rem;
        padding: 0.05rem;
      }
    }
  }
}
</style>
